<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search ref="search"  :config="searchConfig" @search="search" @getHeight="getHeight"/>

    <!-- table区域-begin -->
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-94'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config="tableToolbar"
       :checkbox-config="checkboxConfig"
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <!-- 操作按钮区域 -->
          <div class="table-operator">
<!--            <a-button  @click="handleAdd">新增</a-button>-->
<!--            <a-button v-has="'announcementCen:delete'" @click="batchDel">删除</a-button>-->
            <!--      <a-button type="primary"  @click="startorstop('003')">停用</a-button>-->
<!--            <a-button v-has="'announcementCen:export'" @click="handleExportXls('单表示例')">导出</a-button>-->
          </div>
        </template>

        <template #productName='{ row,rowIndex }'>
          <a @click="handleView(row)">{{row.id}}</a>
        </template>
        <template #feedbackType='{ row }'>
          {{ row.feedbackType == '1' ? '订单问题' : '其它问题' }}
        </template>
        <template #bpmStatus='{ row }'>
          {{ row.bpmStatus == '1' ? '待处理' : '已处理' }}
        </template>
        <template #updateStatus='{ row,rowIndex }'>
          <a-switch  :checked="row.status" size="small" :value="row"  @change="changeStatus($event,row)" />
        </template>
        <template #updateTopStatus='{ row,rowIndex }'>
          <a-switch  :checked="row.isTop" size="small" :value="row"  @change="changeStatus($event,row,true)" />
        </template>
        <template #action='{ row }'>
          <a v-has="'announcementCen:update'" @click='handleView(row)'>审核</a>
          <a-divider type='vertical' />
          <a v-has="'business:log'" href='javascript:' @click='handleBusiness("客诉反馈",row)'>日志</a>
        </template>
        <template #orderNumber='{ row,rowIndex }'>
          <a @click="handleView(row)">{{ row.orderNumber }}</a>
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync='ipagination.current'
            :page-size.sync='ipagination.pageSize'
            :total='ipagination.total'
            :pageSizes='ipagination.pageSizeOptions'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <feedback-modal ref="modalForm" @ok="modalFormOk"></feedback-modal>
    <business-log ref='businessLog'></business-log>
  </a-card>
</template>

<script>
import FormAddEdit from '@comp/view/base-crud/form/FormAddEdit'
  import JSuperQuery from '@/components/cn-form/JSuperQuery.vue'
  import JInput from '@/components/cn-form/JInput.vue'
  import { initDictOptions, filterDictText, filterDictTextByCache } from '@/components/dict/CnDictSelectUtil'
  import { PageListMixin } from '@/mixins/PageListMixin'
  import Vue from 'vue'
  import { filterObj } from '@/utils/util'
  import JTreeSelect from '@/components/cn-form/JTreeSelect'
  import { postAction } from '../../../api/manage'
  // import materialModal from './modules/materialModal'
  import feedbackModal from './modules/FeedbackModal'
  import { getAction } from '@/api/manage'
  import search from '@comp/view/base-crud/search/Search'

  //高级查询modal需要参数

  export default {
    name: 'cusProductGroups',
    mixins: [PageListMixin],
    components: {
      JSuperQuery,
      JInput,
      JTreeSelect,
      feedbackModal,
      search
    },
    // priceAdd
    data() {
      return {
        description: '客诉反馈',
        //字典数组缓存
        sexDictOptions: [],
        importExcelUrl: `${window._CONFIG['domianURL']}/test/cn-formDemo/importExcel`,

        searchConfig:[
          {
            // label:'订单编号',
            type:'input',
            name:'customerCode',
            placeholder:'经销商编码',
          },
          {
            type:'input',
            name:'customerName',
            placeholder:'经销商名称',
          },
          {
            // label:'订单状态',
            type:'a-select',
            name:'bpmStatus',
            option:[{
              name:'待处理',
              value:1
            },{
              name:'已处理',
              value:0
            }],
            placeholder:'请选择状态',
          },
          {
            type: 'j-select',
            name: 'feedbackType',
            dictCode:'feedback_type',
            placeholder: '问题类型',
          },
        ],
        //表头
        columns: [],
        //列设置
        settingColumns: [],
        //列定义  表格改这儿
        defColumns: [
          { type: 'checkbox', width: 60, fixed: 'left' },

          {
            title: '工单编号',
            align: 'center',
            field: 'orderNumber',
            minWidth: 80,
            slots: {
              default: 'orderNumber'
            }
          },
          {
            title: '问题类型',
            align: 'center',
            minWidth: 80,
            field: 'feedbackType',
            slots: { default: 'feedbackType' }
          },
          {
            title: '订单号',
            align: 'center',
            minWidth: 80,
            field: 'orderCode'
          },
          {
            title: '标题',
            align: 'center',
            minWidth: 80,
            field: 'title'
          },
          {
            title: '经销商编号',
            align: 'center',
            minWidth: 80,
            field: 'customerCode'
          },
          {
            title: '经销商名称',
            align: 'center',
            minWidth: 80,
            field: 'customerName'
          },
          {
            title: '所属组织编号',
            align: 'center',
            minWidth: 100,
            field: 'orgCode'
          },
          {
            title: '所属组织名称',
            align: 'center',
            minWidth: 100,
            field: 'orgName'
          },
          {
            title: '经销商负责人编号',
            align: 'center',
            minWidth: 110,
            field: 'userName'
          },
          {
            title: '经销商负责人',
            align: 'center',
            minWidth: 80,
            field: 'realName'
          },
          {
            title: '提交时间',
            align: 'center',
            minWidth: 80,
            field: 'createTime'
          },
          {
            title: '更新人',
            align: 'center',
            minWidth: 80,
            field: 'updateName'
          },
          {
            title: '处理时间',
            align: 'center',
            minWidth: 80,
            field: 'updateTime'
          },
          {
            title: '状态',
            align: 'center',
            field: 'bpmStatus',
            fixed: 'right',
            minWidth: 80,
            slots: { default: 'bpmStatus' }
          },
          {
            title: '操作',
            field: 'action',
            fixed: 'right',
            align: 'center',
            minWidth: 120,
            slots: {
              default: 'action'
            }
          }
        ],
        url: {
          list: window._CONFIG['domianURL'] + '/feedback/cnFeedback/findPageList',
          detail: window._CONFIG['domianURL'] + '/feedback/cnFeedback/getInfo',
          delete: window._CONFIG['domianURL'] + '/feedback/cnFeedback/delete',
          startOrStopUrl: window._CONFIG['domianURL'] + "/feedback/cnFeedback/updateStatus",
          topStartOrStopUrl: window._CONFIG['domianURL'] + "/feedback/cnFeedback/updateIsTop",
          deleteBatch: '/feedback/cnFeedback/deleteInfo',
          exportXlsUrl: '/test/cn-formDemo/exportXls'

        }

      }
    },

    methods: {
      filterDictText,
      startorstop: function(status) {
        if (!this.url.startOrStopUrl) {
          this.$message.error("请设置url启用停用!")
          return;
        }
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');

        } else {
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          var that = this;
          this.$confirm({
            title: "确认修改",
            content: "是否修改选中数据?",
            onOk: function () {
              that.loading = true;
              getAction(that.url.startOrStopUrl, {ids: ids, status: status}).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading = false;
              });
            }
          });
        }
      },
      startorstopByid(status,id,top){
        let that=this
        this.$confirm({
          title: "确认修改",
          content: '是否'+(top?(status==1?'取消置顶':'置顶'):(status==1?'停用':'启动'))+'选中数据？',
          onOk(){
            that.loading = true;
            let type=top?'isTop':'status'
            let url=top?that.url.topStartOrStopUrl:that.url.startOrStopUrl
            getAction(url, {ids: id, [type]:status?0:1}).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.loadData();
                that.onClearSelected();
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.loading = false;
            });
          },
          onCancel(){
            // that.loadData();
            // that.onClearSelected();
          },
        })
      },
      selectCusttype(value) {
        this.$set(this.queryParam, 'custType', value)
      },
      changeStatus(e,item,top){
        let type=top?'isTop':'status'
        this.startorstopByid(item[type],item.id,top)

      },
      handleAdd() {
        this.$refs.modalForm.title='新增'
        this.$refs.modalForm.disableSubmit = false
        this.$refs.modalForm.visible=true
        this.$refs.modalForm.add()
      },
      handleEdit:async function(row) {
        this.$refs.modalForm.title='编辑'
        this.$refs.modalForm.visible=true
        this.$refs.modalForm.disableSubmit = false
        this.$refs.modalForm.edit(row)

      },
      handleView:async function(row) {
        this.$refs.modalForm.edit(row)
        this.$refs.modalForm.title='详情'
        this.$refs.modalForm.visible=true
        this.$refs.modalForm.disableSubmit = true
      },
      getQueryParams() {
        //高级查询器
        let sqp = {}
        if (this.superQueryParams) {
          sqp['superQueryParams'] = encodeURI(this.superQueryParams)
          sqp['superQueryMatchType'] = this.superQueryMatchType
        }
        var param = Object.assign(sqp, this.queryParam, this.isorter, this.filters)

        param.field = this.getQueryField()
        param.current = this.ipagination.current
        param.size = this.ipagination.pageSize
        delete param.birthdayRange //范围参数不传递后台
        return filterObj(param)
      },
      //跳转单据页面
      jump() {
        this.$notification.success('跳转 ： jump')
      },
      onBirthdayChange: function(value, dateString) {
        console.log(dateString[0], dateString[1])
        this.queryParam.birthday_begin = dateString[0]
        this.queryParam.birthday_end = dateString[1]
      },
      //列设置更改事件
      onColSettingsChange(checkedValues) {
        var key = this.$route.name + ':colsettings'
        Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
        this.settingColumns = checkedValues
        const cols = this.defColumns.filter(item => {
          if (item.key == 'rowIndex' || item.field == 'action') {
            return true
          }
          if (this.settingColumns.includes(item.field)) {
            return true
          }
          return false
        })
        this.columns = cols
      },
      initColumns() {
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

        var key = this.$route.name + ':colsettings'
        let colSettings = Vue.ls.get(key)
        if (colSettings == null || colSettings == undefined) {
          let allSettingColumns = []
          this.defColumns.forEach(function(item, i, array) {
            allSettingColumns.push(item.field)
          })
          this.settingColumns = allSettingColumns
          this.columns = this.defColumns
        } else {
          this.settingColumns = colSettings
          const cols = this.defColumns.filter(item => {
            if (item.key == 'rowIndex' || item.field == 'action') {
              return true
            }
            if (colSettings.includes(item.field)) {
              return true
            }
            return false
          })
          this.columns = cols
        }
      }
    },
    created() {
      this.initColumns()
    }

  }
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>